$NG.AllReady(function (page, { useAction, useBeforeClick, useAfterClick, useValuesChange, useClick, useUpdateRow, subscribe, useUpdateRows }) {
    const mstform = $NG.getCmpApi("p_form_tbqkzj_m")
    const dgrid1 = $NG.getCmpApi("")
    const getHeadValue = (str) => mstform.getItem(str).getValue()
    if (!mstform.getItem("u_fid").getValue()) {
        mstform.getItem("u_fid").setValue(generateUUID())
    }
    useBeforeClick((c) => {
        const u_fj = getHeadValue("u_fj")
        const u_tbwj = getHeadValue("u_tbwj")
        const u_kbjl = getHeadValue("u_kbjl")
        const u_sqwts = getHeadValue("u_sqwts")
        const u_bhsmj = getHeadValue("u_bhsmj")
        const nameKey = {
            0: '招标附件',
            1: '投标文件',
            2: '开标记录',
            3: '授权委托书',
            4: '保函扫描件'
        }
        let lock = true
        const keys = [u_fj, u_tbwj, u_kbjl, u_sqwts]
        let err = []
        keys.forEach((item, index) => {
            if (item) {
                const str = item.split("@@")
                console.log(`str`, str);
                if (!str[1] || str[1] == '0') {
                    lock = false
                    err.push(nameKey[index])
                }
            } else {
                lock = false
                err.push(nameKey[index])
            }
        })
        if (!lock) {
            $NG.alert("有附件未上传！" + err.join("、"))
            return false
        }
        setTimeout(() => {
            const str = "Hello 父页面" + JSON.stringify($NG.getCmpApi("p_form_tbqkzj_m").getValues());
            const success = { isOk: true, data: $NG.getCmpApi("p_form_tbqkzj_m").getValues() }
            window.parent.receiveFromIframe(JSON.stringify(success)); // 调用父页面函数
            console.log(`保存成功`,);
        })
        $NG.refresh()
        return true
    }, "save")


    function generateUUID() {
        // UUID v4的格式为：xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
        // 其中y位为8、9、A或B

        // 生成随机16进制数的辅助函数
        function randomHex() {
            // 生成0-0xffff的随机数，转换为16进制并补全4位
            return Math.floor((1 + Math.random()) * 0x10000)
                .toString(16)
                .substring(1);
        }

        // 生成y位的值（8-11之间的随机数，16进制为8-b）
        const y = Math.floor(Math.random() * 4) + 8;

        return (
            randomHex() + '-' +
            randomHex() + '-' +
            '4' + randomHex().substring(1) + '-' +  // 第3段以4开头
            y.toString(16) + randomHex().substring(1) + '-' +  // 第4段以y开头
            randomHex() + randomHex()
        );
    }
})